package de.cbf.cam.dsa.tavern.carte;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

import de.cbf.cam.dsa.tavern.carte.controller.ControllerEditCarte;
import de.cbf.cam.dsa.tavern.carte.model.ModelCarte;
import de.cbf.cam.dsa.tavern.carte.model.generators.AbstractMealGenerator;
import de.cbf.cam.dsa.tavern.carte.model.generators.TestMealGenerator;
import de.cbf.cam.dsa.tavern.carte.ui.CompositeEditCarte;

public class ViewEditCarte extends ViewPart {

	public static final String ID ="de.cbf.cam.dsa.tavern.carte.ViewEdit";
	
	private ControllerEditCarte controller;
	private ModelCarte			model;
	
	public ViewEditCarte() {
		//create controller
		controller = new ControllerEditCarte();
		//create and init model
		model = new ModelCarte();
		//add model to controller
		controller.setModel(model);	
		//add mealGenerator		
		model.setMealGenerator(getPreferredMealGenerator());		
	}

	@Override
	public void createPartControl(Composite parent) {				
		//add composites
		CompositeEditCarte viewCarteEdit = new CompositeEditCarte(parent, SWT.NORMAL);
//		viewCarteEdit.setLayoutData(new GridData(GridData.FILL_BOTH));
		//add view to controller
		controller.setView(viewCarteEdit);				
	}

	@Override
	public void setFocus() {
	}

	private AbstractMealGenerator getPreferredMealGenerator(){
		//TODO (Later) choose by preferences
		return new TestMealGenerator();	
	}
	
	public ControllerEditCarte getController() {
		return controller;
	}

	public ModelCarte getModel() {
		return model;
	}

	public void setModel(ModelCarte model) {
		this.model = model;
		controller.setModel(model);
		model.setMealGenerator(getPreferredMealGenerator());
	}

	public void setController(ControllerEditCarte controller) {
		this.controller = controller;
	}
}
